<%@page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@include file="/common/session.jsp" %>
<!DOCTYPE html>
<html>
<head>
	<title>删除车辆</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<meta name="viewport" content="initial-scale=1.0, minimum-scale=1.0, maximum-scale=2.0, user-scalable=no, width=device-width">
	<LINK type="text/css" rel="stylesheet" href="${ctx}/css/default.css"/>
	<LINK type="text/css" rel="stylesheet" href="${ctx}/js/layer/theme/default/layer.css"/>
	<script src="https://cdn.bootcss.com/jquery/1.9.1/jquery.min.js"></script>
	<script type="text/javascript" src="${ctx}/js/xtable.js"></script>
	<script type="text/javascript" src="${ctx}/dwr/engine.js"></script>
	<script type="text/javascript" src="${ctx}/dwr/util.js"></script>
	<script type='text/javascript' src='${ctx}/dwr/interface/CarRpcService.js'></script>
	<script type="text/javascript" src="${ctx}/js/loading.js"></script>
</head>
<body>
<form>
	<center>
		<table style="width: 50%;" cellpadding="5" cellspacing="5">
			<tr>
				<td>
					<label>车架号：</label>
					<input id="vin" name="vin" property="车辆号" />
				</td>
				<td>
					<button type="button" onclick="getCarPage();">查询</button>
				</td>
			</tr>
		</table>
	</center>
</form>
<SCRIPT LANGUAGE="JavaScript">
	var carThead = new Array(
		new XThead("首图"),
		new XThead("车辆信息"),
		new XThead("商铺信息"),
		new XThead("车辆状态"),
		new XThead("操作")
	);

	var carXTable = new XTable("car", carThead);

	var state_stock_hash = {
		"0":"初始化",
		"10":"入库中",
		"20":"入库",
		"30":"出库中",
		"40":"出库"
	}

	var state_sale_hash = {
		"0":"初始化",
		"10":"申请上架",
		"20":"上架",
		"30":"下架"
	}

	carXTable.XTbodyArray = function (model) {
		var array = new Array(
			new XTbody("car", "<img src='${fdfsPath}" + model.carImageUrl + ".w_150xh_150'  />", "string", null, null, "center"),
			new XTbody("car", model.carTitle + "<br>车驾号：" + model.carVin + "<br>上牌日期：" + model.carLicenceDate.Format("yyyy-MM-dd") + "<br>车牌号：" + model.carPlate, "string", null, null, "center"),
			new XTbody("car", "车商名称：" + model.shop.shopName + "<br>联系方式：" + model.shop.shopMobile, "string", null, null, "center"),
			new XTbody("car", "库存状态：" + state_stock_hash[model.carStockState] + "<br>上架状态：" + state_sale_hash[model.carSaleState], "string", null, null, "center"),
			new XTbody("car", "<a href='#'  style='border-right: 1px  class='contact-input'  onclick=deleteCarInfo('" + model.carId + "')>删除车辆</a>", "string", null, null, "center")
		);
		return array;
	}

	carXTable.getXList = function (page) {
		var car = new Car();
		car.pageIndex = page;
		car.pageSize = carXTable.pageSize;
		car.marketId = '${marketId}';
		car.carVin = dwr.util.getValue("vin");
		CarRpcService.selectCarList(car, function (list) {
			carXTable.addTable(list);
		});
	}

	function getCarPage() {
		var vin = dwr.util.getValue("vin");
		if(vin == "" || vin.length != 17 || vin.toUpperCase().indexOf("I") != -1 || vin.toUpperCase().indexOf("O") != -1 || vin.toUpperCase().indexOf("Q") != -1){
			alert("车驾号错误！")
		}else{
			var car = new Car();
			car.marketId = '${marketId}';
			car.carVin = vin;
			CarRpcService.selectCarNum(car, function (num) {
				carXTable.setTotalPage(num);
			});
		}
	}

	function callbackSelectUserList(list) {
		dwr.util.removeAllOptions("carUserInfo");
		dwr.util.addOptions("carUserInfo", list, "userId", "userName");
	}

	function deleteCarInfo(carId) {
		var r = confirm("确认删除该车辆吗？")
		if (r == true) {
			$.ajax({
				type: "get",      //data 传送数据类型。post 传递
				dataType: 'json',  // 返回数据的数据类型json
				url: "${ctx}/controller/carDel/insertCarDel",  // yii 控制器/方法
				cache: false,
				data: {"carId": carId, "userId": '${userId}'},  //传送的数据
				error: function () {
					alert("数据传输错误");
				}, success: function (data) {
					console.log(data);
					if (data.code != 1) {
						return false
					}
					alert('删除车辆成功！');
					location.reload();
				}
			});
			/* var car = new Car();
			car.carId = carId;
			car.carState = 10;
			CarRpcService.deleteCar(car, function (res) {
				if (res == 1) {
					alert("删除成功");
					location.reload();
				}
			}); */
		}
	}

</SCRIPT>
</body>
</html>
